# Copyright 1999-2007 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

inherit eutils

DESCRIPTION="Tkabber is a Free and Open Source client for the Jabber instant messaging system, written in Tcl/Tk."
HOMEPAGE="http://tkabber.jabber.ru/"
SRC_URI="http://files.jabber.ru/${PN}/${P}.tar.gz
	plugins? ( http://files.jabber.ru/${PN}/${PN}-plugins-${PV}.tar.gz )"

IUSE="crypt plugins ssl"

DEPEND=">=dev-lang/tcl-8.4.0
	>=dev-lang/tk-8.4.0
	>=dev-tcltk/tcllib-1.6
	>=dev-tcltk/bwidget-1.3
	crypt? ( >=dev-tcltk/tclgpgme-1.0 )
	ssl? ( >=dev-tcltk/tls-1.5.0-r1 )
	>=dev-tcltk/tkXwin-1.0"

LICENSE="GPL-2"
KEYWORDS="~x86 ~amd64"
SLOT="0"

src_compile() {
	return 0
}

src_install() {
	dodir /usr/share/tkabber
	cd ${WORKDIR}/${P}/ || die "cd failed!"
	cp -R *.tcl $(find . -maxdepth 1 -type d ! -name '.*') ${D}/usr/share/tkabber

	if use plugins; then
	(
		dodir /usr/share/tkabber/site-plugins
		cd ${WORKDIR}/${PN}-plugins-${PV}
		cp -R $(find . -maxdepth 1 -type d ! -name '.*') \
		${D}/usr/share/tkabber/site-plugins/
		newdoc ${WORKDIR}/${PN}-plugins-${PV}/README README.plugins
	)
	fi

	cat <<-EOF > tkabber
	#!/bin/sh
	TKABBER_SITE_PLUGINS=/usr/share/tkabber/site-plugins \
	exec wish /usr/share/tkabber/tkabber.tcl -name tkabber
	EOF

	domenu ${FILESDIR}/tkabber.desktop
	doicon ${FILESDIR}/tkabber.png

	chmod +x tkabber
	dobin tkabber
	dodoc AUTHORS COPYING ChangeLog INSTALL README
	dohtml README.html
	cp -R doc examples contrib ${D}/usr/share/doc/${PF}
}

pkg_postinst() {
	einfo "There's no UI option to disable emoticons yet, however"
	einfo "you can put the following into your ~/.tkabber/config.tcl"
	einfo
	einfo "hook::add finload_hook {"
	einfo " array unset emoteicons::emoteicons"
	einfo "}"
	einfo
	einfo "By default tkabber uses an internal XML parser. You may want"
	einfo "to use an external one for (dubious) performance reasons,"
	einfo "in which case you may like to emerge dev-tcltk/tdom (and put"
	einfo "\"package require tdom\" in your ~/.tkabber/config.tcl)."
	einfo
	einfo "You may also optionally emerge dev-tcltk/tclx to theoretically"
	einfo "speed some other of tkabber's pure-Tcl operations up,"
	einfo "as you'd get them written in C. Real performance gains are"
	einfo "subject to further tests."
}
